/**
 * 旋转数组的最小数字
 */
public class Solution11 {

    public static int minNumberInRotateArray(int[] nums){
        if (nums.length == 0)
            return 0;
        int l = 0, h = nums.length - 1;
        while (l < h){
            int m = l + (h - l) / 2;
            if (nums[l] == nums[m] && nums[m] == nums[h])
                return minNumber(nums, l, h);
            else if (nums[m] <= nums[h])
                h = m;
            else
                l = m + 1;
        }
        return nums[l];
    }

    private static int minNumber(int[] nums, int l, int h){
        int min = nums[l];
        for (int i = l + 1; i < h; i++){
            if (nums[i] < min)
                min = nums[i];
        }
        return min;
    }

//    public static void main(String[] args){
//        System.out.println(minNumberInRotateArray(new int[]{2, 2, 2, 2, 2, 2, 0, 2}));
//    }
}
